package com.qf.front.biz;

import com.qf.ym.MyUtils;
import com.qf.ym.entity.AddressEntity;
import com.qf.ym.entity.OrderDetailEntity;
import com.qf.ym.entity.OrderEntity;
import com.qf.ym.entity.UserEntity;
import com.qf.ym.mapper.GoodsMapper;
import com.qf.ym.mapper.OrderMapper;
import com.qf.ym.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    GoodsMapper goodsMapper;

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    UserMapper userMapper;


    public OrderEntity createOrder(OrderEntity oe, Integer[] goods) {

        Date date = new Date();
        int aid = oe.getAid();
        UserEntity userEntity = userMapper.selectUser(aid);
        oe.setOid(MyUtils.getUUID());
        oe.setOstatus(1);
        oe.setOcreateDate(date);
        oe.setUser(userEntity);
        boolean order = orderMapper.createOrder(oe);
        if(order){
            orderMapper.createOrderDetail(goods,oe.getOid());

            return oe;
        }

        return null;
    }




    @Override
    public boolean updOstatus(String oid) {
        return orderMapper.updOstatus(oid);
    }

    @Override
    public boolean addAddress(AddressEntity ad) {
        return orderMapper.addAddress(ad);
    }

    @Override
    public List<AddressEntity> showAddress(int aid) {
        return orderMapper.showAddress(aid);
    }

    @Override
    public boolean toPlay(String oid) {
        return orderMapper.toPlay(oid);
    }

    @Override
    public List<OrderEntity> orderList(int aid) {
        return orderMapper.orderList(aid);
    }

    @Override
    public List<OrderDetailEntity> orderDetailList(String oid) {
        return orderMapper.orderDetailList(oid);
    }

}
